
package jweslley.ProblemSetVolumes.VolumeI;

import static java.lang.Math.sqrt;
import jweslley.Problem;
import jweslley.Problem.Status;

/**
 * http://icpcres.ecs.baylor.edu/onlinejudge/external/1/138.html
 *
 * @author  Jonhnny Weslley
 * @version 1.00, 17/10/2008
 */
@Problem(Status.Accepted)
public class StreetNumbers {

	static void doStreetNumbers() {
		int k = 0;
		long left, right, previous, a, b, c, r;
		a = 1;
		while (k < 10) {
			a++;
			left = (a * a + a) / 2;
			previous = left - a;

			b = 2 * a + 1;
			c = -2 * previous;

			r = (long) (-b + sqrt(b * b - 4 * c)) / 2;
			right = ((a + r) * (a + r) + (a + r)) / 2;

			if (left == right - previous) {
				k++;
				System.out.println(rightPad(a) + " " + rightPad(a + r));
			}
		}
	}

	static String rightPad(long l) {
		StringBuilder lt = new StringBuilder(Long.toString(l));
		while (lt.length() < 10) {
			lt.insert(0, ' ');
		}
		return lt.toString();
	}

	public static void main(String[] args) {
		System.out.print(
		"         6         8\n" +
		"        35        49\n" +
		"       204       288\n" +
		"      1189      1681\n" +
		"      6930      9800\n" +
		"     40391     57121\n" +
		"    235416    332928\n" +
		"   1372105   1940449\n" +
		"   7997214  11309768\n" +
		"  46611179  65918161\n"
		);
	}

}
